/* -+- file  ./kf2/Roster/Reveal.cs -+- */
/*
 * kf2 jabber client
 * ~~~~~~~~~~~~~~~~~
 *
 * Copyright (C) 2006-2007 Przemysław Sitek
 * 				<przemyslaw.sitek at wp.pl> 
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */
using System;
using Mono.Unix;
using Habazie.kf2.Core;

namespace Habazie.kf2.GUI
{
	
	///<summary>
	///	Provides various GUI-based utilities
	///</summary>
	public class Reveal
	{
	
		///<summary>
		///	Create appropriate ChatView
		///</summary>
		public static IChatView CreateChatView ()
		{
			bool use_gecko = true;	// FIXME
						
			if (use_gecko) {
				try {
					GeckoChatView view = new GeckoChatView (null); // FIXME
					return view;
				} catch (Exception e) {
					Util.ReportException (e);
				}
			}
			
			return new GtkChatView ();
		}


		/// <summary>
		/// 	Prompt for a input line
		/// </summary>
		public static string Prompt (Gtk.Window parent, string text, string answer)
		{
			Gtk.Dialog win = new Gtk.Dialog (Catalog.GetString ("Question"), parent,
					Gtk.DialogFlags.Modal);

			Gtk.HBox hbox = new Gtk.HBox (false, 6);
			hbox.BorderWidth = 12;

			Gtk.Image image = new Gtk.Image (Gtk.Stock.DialogQuestion, Gtk.IconSize.Dialog);
			hbox.PackStart (image, false, false, 0);

			Gtk.VBox vbox = new Gtk.VBox (false, 6);

			Gtk.Label label = new Gtk.Label (text);
			vbox.PackStart (label, false, false, 0);

			Gtk.Entry entry = new Gtk.Entry ();
			if (answer != null)
				entry.Text = answer;
			vbox.PackStart (entry, false, false, 0);

			hbox.PackStart (vbox, true, true, 0);

			win.VBox.Add (hbox);
			win.ShowAll ();

			win.AddButton (Gtk.Stock.Cancel, Gtk.ResponseType.Cancel);
			win.AddButton (Gtk.Stock.Ok, Gtk.ResponseType.Ok);

			int res = win.Run ();
			string ret = entry.Text;
			win.Destroy ();
			if (res == (int) Gtk.ResponseType.Ok)
				return ret;
			else
				return null;
		}


		public static bool Question (Gtk.Window parent, string text)
		{
			Gtk.Dialog win = new Gtk.Dialog (Catalog.GetString ("Question"), parent,
					Gtk.DialogFlags.Modal);

			Gtk.HBox hbox = new Gtk.HBox (false, 6);
			hbox.BorderWidth = 12;

			Gtk.Image image = new Gtk.Image (Gtk.Stock.DialogQuestion, Gtk.IconSize.Dialog);
			hbox.PackStart (image, false, false, 0);

			Gtk.VBox vbox = new Gtk.VBox (false, 6);

			Gtk.Label label = new Gtk.Label (text);
			vbox.PackStart (label, false, false, 0);

			hbox.PackStart (vbox, true, true, 0);

			win.VBox.Add (hbox);
			win.ShowAll ();

			win.AddButton (Gtk.Stock.No, Gtk.ResponseType.No);
			win.AddButton (Gtk.Stock.Yes, Gtk.ResponseType.Yes);

			int res = win.Run ();
			win.Destroy ();
			if (res == (int) Gtk.ResponseType.Yes)
				return true;
			else
				return false;
		}
	}
}
